home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / MPW Script Tips 1.1.1 / Sample Scripts / MyOpen < prev    next >
Encoding:
Text File  |  1991-08-16  |  1.6 KB  |  45 lines  |  [TEXT/MPS ]

  1. #----------------------------------------------------------------------------------------------------------------------------------------------------
  2. #    MyOpen
  3. #    MPW Shell Script
  4. #    Written by Gina Cherry • August 16, 1991
  5. #    Copyright:    © 1991 by Apple Computer, Inc., all rights reserved.
  6. #    
  7. #    Usage:    MyOpen [file]
  8. #    
  9. #    Function:
  10. #            MyOpen will look through a predefined list of paths for the file specified on the command line.  
  11. #            The list of paths is specified in the shell variable openList, which should be initialized and 
  12. #            exported in the UserStartup file.  If a file is not specifed on the command line, MyOpen will 
  13. #            prompt the user for a file to open.  
  14. #----------------------------------------------------------------------------------------------------------------------------------------------------
  15.  
  16. #    Make sure there's no more than one parameter.            
  17.     If {#} > 1
  18.         Echo "### Usage: {0} [file]" >> Dev:StdErr
  19.         Exit 1
  20.     End
  21.  
  22. #    Don't exit on error.
  23.     Set Exit 0        
  24.  
  25. #    If a parameter is given, set file to the parameter.    
  26.     If {#} == 1
  27.         Set file "{1}"
  28. #    Otherwise, prompt the user for a file to open.
  29.     Else 
  30.         Set file "`Request "Open what file?"`"
  31.         Exit If "{file}" == ""
  32.     End
  33.  
  34. #    Loop through paths in openList    
  35.     For path in {openList}
  36.         #    Try to open file using current path.
  37.             Open "{path}{file}" ≥ Dev:Null
  38.         #    If open succeeds, exit script.
  39.             Exit If {Status} == 0
  40.     End
  41.  
  42. #    If the execution of the script reaches this point, the file does not exist in any of the directories 
  43. #    defined in openList.  In that case, write error message and exit script with status 2.    
  44.     Echo "### {0}: File {file} not found." >> Dev:StdErr
  45.     Exit 2